{{ template "head" . }}

{{ template "prom_right_table_head" }}
<tr>
  <th>Validators</th>
  <th>{{ template "prom_query_drilldown" (args "sum(up{job='validators'})") }} / {{ template "prom_query_drilldown" (args "count(up{job='validators'})") }}</th>
</tr>
{{ template "prom_right_table_tail" }}

{{ template "prom_content_head" . }}
<h1>Validators Overview</h1>

<table class="table table-condensed table-striped table-bordered" style="width: 75%">
<tr>
  <th>Validators</th>
  <th>Up</th>
  <th>Connected<br/>Peers</th>
  <th>Round Number</th>
  <th>Uptime</th>
  <th>CPU Used</th>
  <th>Memory<br/> Available</th>
  <th>Revision</th>
</tr>
{{ range query "up{job='validators'}" | sortByLabel "instance" }}
<tr>
  <td><a href="validator-overview.html?address={{ .Labels.address }}">{{ reReplaceAll "(.*?://)([^:/]+?)(:\\d+)?/.*" "$2" .Labels.peer_id }}</a></td>

  <td{{ if eq (. | value) 1.0 }}>Yes{{ else }} class="alert-danger">No{{ end }}</td>

  <td>{{ template "prom_query_drilldown" (args (printf "network_gauge{op='connected_peers',job='validators',instance='%s'}" .Labels.instance) "") }}</td>

  <td> Total: {{ template "prom_query_drilldown" (args (printf "consensus_gauge{op='current_round',job='validators',instance='%s'}" .Labels.instance) "") }}<br/>
       Rate: {{ template "prom_query_drilldown" (args (printf "rate(consensus_gauge{op='current_round',job='validators',instance='%s'}[1m])" .Labels.instance) "" "printf.1f") }}</td>

  <td>Instance: {{ template "prom_query_drilldown" (args (printf "time() - node_boot_time_seconds{job='validator_nodes',address='%s'}" .Labels.address) "" "humanizeDuration") }}
    <br />
    Container: {{ template "prom_query_drilldown" (args (printf "time() - ecs_start_time_seconds{job='validator_nodes',address='%s'}" .Labels.address) "" "humanizeDuration") }}
  </td>

  <td>{{ template "prom_query_drilldown" (args (printf "100 * (1 - avg by(address)(irate(node_cpu_seconds_total{job='validator_nodes',mode='idle',address='%s'}[5m])))" .Labels.address) "%" "printf.1f") }}</td>

  <td>{{ template "prom_query_drilldown" (args (printf "node_memory_MemFree_bytes{job='validator_nodes',address='%s'} + node_memory_Cached_bytes{job='validator_nodes',address='%s'} + node_memory_Buffers_bytes{job='validator_nodes',address='%s'}" .Labels.address .Labels.address .Labels.address) "B" "humanize1024") }}</td>
<td>{{ with query (printf "build_info{address='%s'}" .Labels.address) }}{{. | first | label "revision" | printf "%.8s"}}{{end}}</td>
</tr>
{{ else }}
<tr><td colspan=4>No nodes found.</td></tr>
{{ end }}


<table style="width: 90%;" cellpadding="10px">
  <tr>
    <th>Transactions rate (Consensus) </th>
    <th>Who's the proposer? (Consensus)</th>
  </tr>
  <tr>
    <td id="committedTxns" width=50%>
  <script>
  new PromConsole.Graph({
      node: document.querySelector("#committedTxns"),
      expr: "avg(irate(consensus{op='committed_txns_count'}[1m]))",
      width: "400px",
      yAxisFormatter: PromConsole.NumberFormatter.humanizeNoSmallPrefix,
      yHoverFormatter: PromConsole.NumberFormatter.humanizeNoSmallPrefix,
      yTitle: 'TSP',
      xTitle: 'Committed Transactions Rate'
  })
  </script>
    </td>

    <td id="proposalsCount" width=50%>
  <script>
  new PromConsole.Graph({
      node: document.querySelector("#proposalsCount"),
      expr: "avg(irate(consensus{op='proposals_count'}[1m])) by (peer_id)",
      width: 400,
      yAxisFormatter: PromConsole.NumberFormatter.humanizeNoSmallPrefix,
      yHoverFormatter: PromConsole.NumberFormatter.humanizeNoSmallPrefix,
      yTitle: 'Active Proposer',
      xTitle: 'Who is active proposer?'
  })
  </script>
    </td>
  </tr>
</table>


{{ template "prom_content_tail" . }}

{{ template "tail" }}
